package com.dao;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.user.User;
import com.util.DateBaseUtil;


public class UserDao {
	public void selectuser() throws SQLException{
		Connection conn = DateBaseUtil.getConnection();
		String sql="select b.name,a.info,a.date from fatie a,user b where b.id=a.fid";
		PreparedStatement ps=conn.prepareStatement(sql);
		ResultSet rs=ps.executeQuery(sql);
	    List<User> users=new ArrayList<User>();
		while(rs.next()){
			User s=new User();
			
			s.setInfo(rs.getString("info"));
			s.setName(rs.getString("name"));
			s.setDate(rs.getString("date"));
			ps.execute();
			
			users.add(s);
		}
		for (User user : users) {
			System.out.println(user.getName());
			
		}
		
	}
	
	public void insetuser(User user) throws SQLException{
		Connection conn = DateBaseUtil.getConnection();
		String sql="insert into user(name,password,Email)values(?,?,?)";
		PreparedStatement ps=conn.prepareStatement(sql);
		ps.setString(1, user.getName());
		ps.setString(2, user.getPassword());
		ps.setString(3, user.getEmail());
		ps.executeUpdate();
		
	}

}
